Execute (UNIX) Command {R}←⎕SH Y

⎕SH executes a UNIX shell or a Windows Command Processor.  ⎕SH is a synonym of ⎕CMD.  Either function may be used in either environment (UNIX or Windows) with exactly the same effect.  ⎕SH is probably more natural for the UNIX user.  This section describes the behaviour of ⎕SH and ⎕CMD under UNIX.  See Execute Windows Command for a discussion of the behaviour of these system functions under Windows.

The system commands )SH and )CMD provide similar facilities.

Y must be a simple character scalar or vector representing a UNIX shell command.  R is a nested vector of character vectors.

Y may be any acceptable UNIX command. If the command does not produce any output, R is 0⍴⊂'' but the result is suppressed if not explicitly used or assigned.  If the command has a non-zero exit code, then APL will signal a DOMAIN ERROR.  If the command returns a result and has a zero exit code, then each element of R will be a line from the standard output (stdout) of the command.  Output from standard error (stderr) is not captured unless redirected to stdout.

Examples

      ⎕SH'ls'
FILES WS temp
 
      ⎕SH 'rm WS/TEST'
 
      ⎕SH 'grep bin /etc/passwd ; exit 0'
bin:!:2:2::/bin:
 
      ⎕SH 'apl MYWS <inputfile >out1 2>out2 &'

Note:

This function is disabled and instead generates a DOMAIN ERROR if the RIDE_SPAWNED parameter is non-zero. This is designed to prevent it being invoked from a RIDE session which does not support this type of user interface. For further details, see the RIDE User Guide.

Under macOS and Linux, if the configuration parameter ENABLE_CEF is 1, Auxiliary Processors cannot be used (they hang on error). The default value is 1 unless you are not running under a desktop (for example, you are running Dyalog in a PuTTY session when the default is 0).